import Vue from 'vue'
//登录

Vue.prototype.$login = (userid,token,name)=>{
	localStorage.setItem('userid',userid)
	localStorage.setItem('token',token)
	localStorage.setItem('name',name)
	localStorage.setItem('auth',true)
}

//退出登录
Vue.prototype.$logout = ()=>{
	localStorage.removeItem('userid')
	localStorage.removeItem('token')
	localStorage.removeItem('name')
	localStorage.removeItem('auth') 
}

//获取用户信息
Vue.prototype.$getUser = ()=>{
	let data = {
		userid:localStorage.getItem('userid') || null,
		token:localStorage.getItem('token') || null,
		name:localStorage.getItem('name') || null,
		auth:Boolean(localStorage.getItem('auth') || false)
	}
	return data
}
//是否登录 true登录
Vue.prototype.$isLogin = ()=>{
	let userid = Vue.prototype.$getUser().userid
	return !Vue.prototype.$isNull(userid)
}

//判断传过来的值是否为空
Vue.prototype.$isNull = (data)=>{      
	if(data == '' || data == null || data == undefined || data === {}){
		return true
	}
	return false
}

//回到顶部
Vue.prototype.$returnTop = () =>{
	if(document.body.scrollTop){
		document.body.scrollTop = 0
	}else {
		document.documentElement.scrollTop = 0
	}
}
Vue.prototype.$scrollTo = (x = 0, y = 0, type = 'smooth') => {
	window.scrollTo({
		top: x,
		left: y,
		behavior: type // 滚动行为：smooth平滑滚动，instant瞬间滚动，默认值auto，等同于instant
	})
}